<?php

function actionMenu($controller,$menu){
    echo $class = ($controller == $menu) ? 'action':'';
}
function actionSeta($controller,$menu){
    echo $class = ($controller == $menu) ? '<span>&#9660;</span>':'<span>&nbsp;</span>';
}

$db = Zend_Db_Table_Abstract::getDefaultAdapter();

//aluno
if($this->storage->read()->TUS_ID == 2){ 

    $sessao = new Zend_Session_Namespace('Aluno');

    Zend_Loader::loadClass('aluno','library'); 
    Zend_Loader::loadClass('dominio','library');

    
    $query = 'SELECT SQL_CACHE n.NRT_NOM,cb.CBS_NOM,c.TUR_ID,c.CUR_ANO,c.CUR_SEM '
            .' FROM MATRICULA m, CURSOBASE cb, CURSO c, NUMEROTURMA n '
            .' WHERE m.ALU_ID = '.$sessao->aluno['ALU_ID'].' '
            .' AND m.CUR_ID = c.CUR_ID AND c.CBS_ID = cb.CBS_ID AND c.CUR_TRM = n.NRT_ID '
            .' AND m.MAT_STA = 1';
    $row = $db->fetchRow($query);

    if(isset($row['NRT_NOM'])) $turma = $row['CBS_NOM'].' '.$row['NRT_NOM'];
    else $turma = '';
?>

    <div class="st-tp-menu">
        <div class="content-it-br"> 
            <?php
                $img = glob('public/upload/aluno/'.$sessao->aluno['ALU_ID'].'_ead.*'); 
                if(!isset($img[0])) $img[0] = 'public/media/images/aluno_ead.png';
            ?>
            <a class="itl-conf" href="<?php echo $this->baseUrl($this->modulo.'/minhaconta/foto'); ?>">
                <img src="<?php echo $this->urlbase;?>/<?php echo $img[0]; ?>" />
            </a>

            <div class="br-usuario">
                <div class="nome"><?php echo $this->storage->read()->USU_NOME; ?></div>
                <span><strong><span><strong>Turma: <?php echo $turma; ?></strong></span>
            </div>

            <a class="itr-menu" onclick="if(confirm('Deseja sair?')) location = '<?php echo $this->baseUrl($this->modulo.'/auth/logout')?>';" href="javascript:void(0)">Sair</a>
            <a class="itr-conf" href="<?php echo $this->baseUrl($this->modulo.'/minhaconta'); ?>"></a>
        </div>
    </div>

    <?php 
    $sessao = new Zend_Session_Namespace('banner');
    
    if(is_array($sessao->imgs)){
        $imgs = $sessao->imgs;
    }else{
        $query = 'SELECT SQL_CACHE EBN_ID FROM EAD_BANNER WHERE EBN_STA = 1 ORDER BY EBN_ORD ASC';
        $result = $db->fetchAll($query);  
        foreach($result as $key => $row){
            $img = glob('public/upload/eadbanner/'.$row['EBN_ID'].'.*'); 
            if(isset($img[0])) $imgs[$key] = $img[0]; 
        }
        $sessao->imgs = $imgs;
    }
    
    if(isset($imgs[0])){

        if($sessao->id == '') $sessao->id = 0;
        $total = count($imgs) - 1;
        //$rand = rand(0, $total);
        $rand = $sessao->id;
        $img = $imgs[$rand];

        if($sessao->id >= $total) $sessao->id = 0;
        else $sessao->id = $sessao->id + 1;

        if($img > ''){ 
        $EBN_ID = str_replace('public/upload/eadbanner/','', $img);
        $EBN_ID = explode('.', $EBN_ID);
        $EBN_ID = $EBN_ID[0];
        $query = 'SELECT SQL_CACHE EBN_LNK FROM EAD_BANNER WHERE EBN_ID = "'.$EBN_ID.'" AND EBN_STA = 1 ORDER BY EBN_ORD ASC';
        $row = $db->fetchRow($query);     
    ?>

        <?php /* <img src="<?php echo $this->urlbase.'/'.$img; ?>" height="200px" width="100%" /> */ ?>
        <?php if(strlen($row['EBN_LNK']) > 0){ ?> <a href="<?php echo $row['EBN_LNK'];?>" target="_blank" ><?php } ?>         
        <div class="banner" style="background-image: url('<?php echo $this->urlbase.'/'.$img; ?>');"></div>
        <?php if(strlen($row['EBN_LNK']) > 0){ ?> </a><?php } ?> 
    <?php
        } 
    } 
    ?>
    <div class="st-menu"> 
        <ul class="mn_ul">
            <li class="mn_li"><a class="mn_a <?php echo actionMenu($this->controller,'index');?>" href="<?php echo $this->baseUrl($this->modulo.'/'); ?>">Início <?php echo actionSeta($this->controller,'index');?></a></li>
            <li class="mn_li men-men-mat"> 
                <a class="mn_a <?php echo actionMenu($this->controller,'materiais');?>" href="javascript:void(0)<?php //echo $this->baseUrl($this->modulo.'/materiais'); ?>">Materiais <?php echo actionSeta($this->controller,'materiais');?></a>   
                <?php  echo $this->partial('topo_submenu_mat.phtml', array('modulo' => $this->modulo)); ?>
            </li>
            <li class="mn_li"><a class="mn_a <?php echo actionMenu($this->controller,'linkuteis');?>" href="<?php echo $this->baseUrl($this->modulo.'/linkuteis'); ?>">Links Úteis <?php echo actionSeta($this->controller,'linkuteis');?></a></li>
            <li class="mn_li"><a class="mn_a <?php echo actionMenu($this->controller,'listaexercicio');?>" href="<?php echo $this->baseUrl($this->modulo.'/listaexercicio'); ?>">Lista de Testes <?php echo actionSeta($this->controller,'listaexercicio');?></a></li>
            <li class="mn_li"><a class="mn_a <?php echo actionMenu($this->controller,'listasimulado');?>" href="<?php echo $this->baseUrl($this->modulo.'/listasimulado'); ?>">Simulado <?php echo actionSeta($this->controller,'listasimulado');?></a></li>
        </ul>
    </div>
    
<?php 
}else //professo
if($this->storage->read()->TUS_ID == 3){

    
function actionMenuPrf($controller,$menu){
    echo $class = ($controller == $menu) ? 'class="action"':'';
}
        
?>
    
    <div class="st-tp-menu">
        <div class="content-it-br"> 
            <?php
                //$img = glob('public/upload/aluno/'.$sessao->aluno['ALU_ID'].'_ead.*'); 
                $img = array();
                if(!isset($img[0])) $img[0] = 'public/media/images/aluno_ead.png';
            ?>
            <a class="itl-conf" href="javascript:void(0);">
                <img src="<?php echo $this->urlbase;?>/<?php echo $img[0]; ?>" />
            </a>

            <div class="br-usuario">
                <div class="nome"><?php echo $this->storage->read()->USU_NOME; ?></div>
                <span><strong>Status:</strong> Professor</span>
            </div>

            <a class="itr-menu" onclick="if(confirm('Deseja sair?')) location = '<?php echo $this->baseUrl($this->modulo.'/auth/logout')?>';" href="javascript:void(0)">Sair</a>
            <a class="itr-conf" href="<?php echo $this->baseUrl($this->modulo.'/minhaconta'); ?>"></a>

        </div>
    </div>

    <div class="st-menu-prf"> 
        <ul>
            <li><a class="m1" href="<?php echo $this->baseUrl($this->modulo.'/'); ?>" <?php echo actionMenuPrf($this->controller,'index');?>>Início</a></li>
            <li><a class="m2" href="<?php echo $this->baseUrl($this->modulo.'/repositorio'); ?>" <?php echo actionMenuPrf($this->controller,'repositorio');?>>Meus Conteúdos</a></li>
            <li><a class="m3" href="<?php echo $this->baseUrl($this->modulo.'/publicacao'); ?>" <?php echo actionMenuPrf($this->controller,'2');?>>Publicar Tópicos</a></li>
            <li><a class="m4" href="<?php echo $this->baseUrl($this->modulo.'/enviarlinks'); ?>" <?php echo actionMenuPrf($this->controller,'3');?>>Publicar Links</a></li>
            <li><a class="m5" href="<?php echo $this->baseUrl($this->modulo.'/listaexercicioprf'); ?>" <?php echo actionMenuPrf($this->controller,'4');?>>Lista de Testes</a></li>
        </ul>
    </div>
<?php } ?> 